package com.doys.myfirstapp;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class ScanCodeBroadcastReceiver extends BroadcastReceiver {
    private OnReceiveCode onReceive;

    @Override
    public void onReceive(Context context, Intent intent) {
        String code = "";
        if (code.length() > 0) {
            onReceive.notifyScan(code);
        }

        code += "action = " + intent.getAction() + ";    ";

        code += "getDataString = " + intent.getDataString() + ";    ";

        code += "c = " + intent.getStringExtra("c") + ";    ";
        code += "k = " + intent.getStringExtra("k") + ";    ";
        code += "END";

        code = intent.getStringExtra("msg");

        if ("com.android.server.scannerservice.broadcast".equals(intent.getAction())) {
            code = intent.getStringExtra("scannerdata");
        }
        onReceive.notifyScan(code);
    }

    interface OnReceiveCode {
        void notifyScan(String Code);
    }
    public void setOnReceive(OnReceiveCode onReceive) {
        this.onReceive = onReceive;
    }
}
